#ifndef __RISCV64_REG_H__
#define __RISCV64_REG_H__

#include <common.h>

static inline int check_reg_idx(int idx) {
  IFDEF(CONFIG_RT_CHECK, assert(idx >= 0 && idx < 32));
  return idx;
}

static inline int check_csr_idx(int idx) {
  if (idx == 0x305)//mtvec
	return 0;
  else if (idx == 0x341)//mepc
	return 1;
  else if (idx == 0x300)//mstatus
	return 2;
  else if (idx == 0x342)//mcause
	return 3;
  else if (idx == 0x304)//mcause
	return 4;
  else if (idx == 0x344)//mcause
	return 5;
  else {
  	  assert(0);
	  return 0;
  }

}

#define gpr(idx) (cpu.gpr[check_reg_idx(idx)])
#define csr(idx) (cpu.csr[check_csr_idx(idx)])


static inline const char* reg_name(int idx, int width) {
  extern const char* regs[];
  return regs[check_reg_idx(idx)];
}

#endif
